<?php
class Web_View_Helper_HoraEntrega2
	extends Zend_View_Helper_Abstract
{
	public function horaEntrega2( $negocio , $tipo ) 
	{
		$idNegocio = $negocio->getId();
	    
		$id = "fechaEntrega-{$idNegocio}-{$tipo}";
		$value = $this->view->rememberedOpcion( $id );
		
	    if ( ! $negocio->programado ){
	        $horariosHoy = $negocio->horariosDeliveryHoy();
	        
    	    $attribs = null;
    		
    		if(empty($horariosHoy)){
    			$horariosHoy[null] = $this->view->translate("sorryWeAreClosing");
    			$attribs = array('style' => 'width:210px;','disabled' => 'disabled');
    		}
    		
    		return $this->view->formSelect( $id, $value, $attribs, $horariosHoy);
	        
	    } else {
	    
	        $Zend_Date = new Zend_Date();
	        
	        $optionsDay = array();
	        $optionsHours = array(); 
	        
	        $horariosWeek = $negocio->horariosWeek( $tipo );
		
	        $n = 1;
	        
	        foreach ( $horariosWeek as $date=>$horarios ){
	        
	            $year = substr( $date,  0, 4);    
	            $month = substr( $date,  4, 2);    
	            $day = substr( $date,  6, 2);    
	            
	            
	            $Zend_Date->setYear($year);
	            $Zend_Date->setMonth($month);
	            $Zend_Date->setDay($day);
	            
	            if ($n==1){
	                $optionsDay[] = $this->view->translate('today');
	            }elseif($n==2){
	                $optionsDay[] = $this->view->translate('tomorrow');
	            }else{
	                $optionsDay[] = ucfirst($Zend_Date->toString( Zend_Date::WEEKDAY . ' ' . Zend_Date::DAY));
	            }
	            
	            
	            $optionsHours = $optionsHours + $horarios;
	            
	            $n++;
	        
	        }
	        
	        return $this->view->formSelect( "diaEntrega-{$idNegocio}-{$tipo}", $value, null, $optionsDay) . $this->view->formSelect( $id, $value, null, $optionsHours);
	    }
	}
}